# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=desync
pkgver=0.9.5
pkgrel=1
pkgdesc="Alternative casync implementation"
arch=(loong64 x86_64)
url="https://github.com/folbricht/desync"
license=(BSD)
depends=(glibc)
makedepends=(go)
source=($pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz)
sha512sums=('650b397e218d852ceb8e0df5ebc2c8177f607f6e52017d075e746c358e0a1d110cfb0e893760eb86fdf72f428ea12a1cd5cc3843e6569e1f078a139e08d07543')
b2sums=('cb29dd3f11660c9c83f7683df7624d3d934b071598a308d41b0b3685e9c3a57262b12ba4cff989f2f39645a07a69cf9aff943516e6187280d92b05411572d099')

build() {
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export CGO_LDFLAGS="$LDFLAGS"
  export GOPATH="$srcdir"
  export GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"

  cd $pkgname-$pkgver
  go build -ldflags "-compressdwarf=false -linkmode external" -o $pkgname ./cmd/$pkgname
}

check() {
  cd $pkgname-$pkgver
  go test ./cmd/$pkgname
}

package() {
  cd $pkgname-$pkgver
  install -vDm 755 $pkgname -t "$pkgdir/usr/bin/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
